﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Immunities
{
    public class ImmunityUpdRequestHandler : IRequestHandler<ImmunityUpdRequestModel, APIResult>
    {
        private readonly IBaseRepository<Immunity> immunityRepository;
        private readonly IMapper mapper;
        public ImmunityUpdRequestHandler(IBaseRepository<Immunity> immunityRepository, IMapper mapper)
        {
            this.immunityRepository = immunityRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(ImmunityUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            Immunity immunity = mapper.Map<Immunity>(request);
            request.Creator = "阿萨德";
            request.CreateTime=DateTime.Now;
            immunityRepository.Update(immunity);

            return Task.FromResult(result);
        }
    }
    public class ImmunityUpdRequestModel : IRequest<APIResult>
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        public int FeedingDays { get; set; }
        public string ImmunityType { get; set; }
        public string ImmunityMethod { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}
